

const http = require("http");
const fs = require("fs");

http.createServer(function (request, response) {
    var url = request.url;

    if (url == "/test.html") {
        const html = fs.readFileSync("test.html", "utf-8");
        response.writeHead(200, {
            "Content-Type": "text/html"
        });
        response.end(html);
    }

    if (url == "/script.js") {
        response.writeHead(200, {
            "Content-Type": "text/javascript",
            "Cache-Control": "max-age=20"
        });
        var jsStr = "console.log('script.js 加载完成')"
        response.end(jsStr);
    }
    console.log(request.headers["user-agent"]);

}).listen(9000);

console.log("server linstening on 9000")


